import { swap } from './utils'

function insertionSort (arr) {
  if (arr == null || arr.length < 2) {
    return
  }
  for (let i = 1; i < arr.length; i++) {
    for (let j = i - 1; j > 0 && arr[j] > arr[j + 1]; j--) {
      swap(arr, j, j + 1)
    }
  }
}

const arr = [1, 4, 3, 2, 5, 7, 6]
insertionSort(arr)
console.log(arr)
